package cn.edu.hcnu.controller;

import cn.edu.hcnu.service.SendEmailService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @description:
 * @author: Administrator
 * @time: 2023/6/19 17:57
 */
@Controller
public class SecurityController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private SendEmailService sendEmailService;

    @GetMapping("/detail/{type}/{path}")
    public String toDetail(@PathVariable("type") String type, @PathVariable("path") String path) {
        return "detail/" + type + "/" + path;
    }

    @GetMapping("/userLogin")
    public String toLoginPage() {
        return "login/login";
    }

    @GetMapping("/toIndex")
    public String toIndex() {
        rabbitTemplate.convertAndSend("2020101856exchange_topic", "2020101856routing_topic", "登录成功");
        long start = System.currentTimeMillis();
        sendEmailService.sendEmailMessage("2291649168@qq.com", "登录成功", "已经登录");
        long end = System.currentTimeMillis();
        System.out.println("发送邮件耗时：" + (end - start) + "ms");
        return "index";
    }

    @GetMapping("/")
    public String index() {

        toIndex();
        return "index";
    }

    @GetMapping("/mylogout")
    public String mylogout() {
        return "login/login";
    }
}
